package com.celesea.workflow.core.entity;

import com.celesea.framework.util.Version;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.Table;
import java.util.Calendar;
import java.util.Date;

/**
 * 流程实例
 *
 * @author JackYuan
 * @create 2017-11-05 16:28
 */
@Version
@Table(name = "wf_instance")
public class WorkflowInstance extends Workflow {

    @Column(name = "`wf_type`", columnDefinition = "流程类型", nullable = false, updatable = false)
    private Integer wfType;

    @Column(name = "`wf_data_id`", columnDefinition = "流程数据主键", nullable = false, updatable = false)
    private String wfDataId;

    @Column(name = "`wf_id`", columnDefinition = "流程定义ID", nullable = false, updatable = false)
    private String wfId;

    @Column(name = "`wf_define_code`", columnDefinition = "流程定义编码", nullable = false, updatable = false)
    private String wfDefineCode;

    @Column(name = "`wf_define_version`", columnDefinition = "流程定义版本号", nullable = false, updatable = false)
    private Long wfDefineVersion;

    @Column(name = "`wf_form_code`", columnDefinition = "流程表单编码", nullable = false, updatable = false)
    private String wfFormCode;

    @Column(name = "`wf_form_version`", columnDefinition = "流程表单版本号", nullable = false, updatable = false)
    private Integer wfFormVersion;

    @Column(name = "`active_node_id`", columnDefinition = "当前节点id")
    protected String activeNodeId;

    @Column(name = "`active_node_name`", columnDefinition = "当前节点名称")
    protected String activeNodeName;

    @Column(name = "`summary`", columnDefinition = "流程摘要")
    protected String summary;

    @Column(name = "`last_time`", columnDefinition = "最后更新时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    protected Date lastTime;

    public WorkflowInstance() {
    }

    public WorkflowInstance(WorkflowDefine define, Workflow entity) {
        this.wfId = define.getId();
        this.wfDefineCode = define.getCode();
        this.wfDefineVersion = define.getVersion();
        this.activeNodeId = define.getStartNodeId();
        this.activeNodeName = define.getStartNodeName();
        this.lastTime = Calendar.getInstance().getTime();

        this.applyId = entity.getApplyId();
        this.applyName = entity.getApplyName();
        this.applyDeptId = entity.getApplyDeptId();
        this.applyDeptName = entity.getApplyDeptName();
        this.workflowStatus = WorkflowStatus.DRAFT.getCode();
        //TODO 表单信息
    }

    public void activeWorkflowNode(WorkflowNode node) {
        this.activeNodeId = node.getId();
        this.activeNodeName = node.getName();
        this.workflowStatus=node.getStatus();
        this.lastTime = Calendar.getInstance().getTime();
    }


    public Integer getWfType() {
        return wfType;
    }

    public void setWfType(Integer wfType) {
        this.wfType = wfType;
    }

    public String getWfDataId() {
        return wfDataId;
    }

    public void setWfDataId(String wfDataId) {
        this.wfDataId = wfDataId;
    }

    public String getWfDefineCode() {
        return wfDefineCode;
    }

    public void setWfDefineCode(String wfDefineCode) {
        this.wfDefineCode = wfDefineCode;
    }

    public Long getWfDefineVersion() {
        return wfDefineVersion;
    }

    public void setWfDefineVersion(Long wfDefineVersion) {
        this.wfDefineVersion = wfDefineVersion;
    }

    public String getWfFormCode() {
        return wfFormCode;
    }

    public void setWfFormCode(String wfFormCode) {
        this.wfFormCode = wfFormCode;
    }

    public Integer getWfFormVersion() {
        return wfFormVersion;
    }

    public void setWfFormVersion(Integer wfFormVersion) {
        this.wfFormVersion = wfFormVersion;
    }

    public String getActiveNodeId() {
        return activeNodeId;
    }

    public void setActiveNodeId(String activeNodeId) {
        this.activeNodeId = activeNodeId;
    }

    public String getActiveNodeName() {
        return activeNodeName;
    }

    public void setActiveNodeName(String activeNodeName) {
        this.activeNodeName = activeNodeName;
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public Date getLastTime() {
        return lastTime;
    }

    public void setLastTime(Date lastTime) {
        this.lastTime = lastTime;
    }

    public String getWfId() {
        return wfId;
    }

    public void setWfId(String wfId) {
        this.wfId = wfId;
    }
}
